import { AdvertisementType } from "@/api/advertisement/AdvertisementModel";
import useInstance from "@/tools/useInstance";
import { EditType,FuncList } from "@/type/BaseType";
import { ref } from "vue";
import { deleteAdvApi } from "@/api/advertisement";
import { ElMessage } from "element-plus";

export default function useAdv(getList:FuncList){
    const {global} = useInstance()
    //新增的弹框的ref属性
    const addRef = ref<{show:(type:string,row?:AdvertisementType)=>void}>();
    //新增
    const addBtn = ()=>{
        addRef.value?.show(EditType.ADD)
    }
    //编辑
    const editBtn = (row:AdvertisementType)=>{
        addRef.value?.show(EditType.EDIT,row)
    }
    //删除
    const deleteBtn = async(row:AdvertisementType)=>{
        const flag = await global.$messageBox('确定删除该数据吗')
        if(flag){
            let result = await deleteAdvApi(row.advId)
            if(result && result.code == 200){
                ElMessage.success(result.msg)
                //刷新列表
                getList()
            }
        }
    }
    return {
        addRef,
        addBtn,
        editBtn,
        deleteBtn
    }
}